#Reverse the words given per line. L letters, W words
#first line read in gives number of test cases



inFile = open(input("Enter file name"))
outFile = open("output.txt",'w')
txt = inFile.read()
inFile.close()

print "**"

#Cut txt into a list of line by line pieces
allTxtLines = txt.splitlines()
txtLines = allTxtLines[1:]

#take the first piece get the number of remaining lines from that information
numOfLines = int(allTxtLines[0])

#reverse and print out the remaining number of lines
linecount = 1
for line in txtLines:
    lineWords = line.split()
    revLineWords = []
    for word in range(-1,-1*len(lineWords)-1,-1):
        revLineWords.append(lineWords[word])

    outFile.write('Case #')
    outFile.write(str(linecount))
    outFile.write(': ')
    [(outFile.write(str(word)),
      outFile.write(' ')) for word in revLineWords[:-1]]

    
##    outFile.write('Case #')
##    outFile.write(str(numOfLines))
##    outFile.write(':')
    outFile.write(revLineWords[-1])
    if linecount < numOfLines:
        outFile.write('\n')
    print revLineWords
    linecount += 1
outFile.close()

